﻿Function Get-InstalledSoftware
{ 
    [cmdletbinding(SupportsShouldProcess=$True)]
    Param()
    Begin
    {
        $watch = [system.diagnostics.stopwatch]::StartNew() 
        write-verbose "Begin Get-InstalledSoftware $Name"
    }
    End
    {
        write-verbose "Begin Get-InstalledSoftware $Name"
        $watch.Stop();
        Write-Verbose "Get-InstalledSoftware duration : $($watch.Elapsed)"
    }
    Process
    {
        $uninstallKeyPath="software\microsoft\windows\currentversion\uninstall\"

        $lstApplications = Get-ChildItem -Path "hklm:\$($uninstallKeyPath)"

        $lstApplications | ForEach-Object -Process {

            $application = New-Object -TypeName PSObject -Property @{Name=$($_.Name.Replace("HKEY_LOCAL_MACHINE","").Replace($uninstallKeyPath,""))}

            $application | Add-Member -MemberType NoteProperty -Name "DisplayName" -Value $($_.GetValue("DisplayName"))

            $application | Add-Member -MemberType NoteProperty -Name "DisplayVersion" -Value $($_.GetValue("DisplayVersion"))

            $application | Add-Member -MemberType NoteProperty -Name "InstallLocation" -Value $($_.GetValue("InstallLocation"))

            $application | Add-Member -MemberType NoteProperty -Name "Publisher" -Value $($_.GetValue("Publisher"))

            Write-Output $application

        }
    }
}